package work.parabola.keyboardswitch.pojo.query.keyswitch;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import work.parabola.keyboardswitch.common.ServerResponse;

@Data
@ToString
@EqualsAndHashCode
public class AddSwitchQuery {

    private String name;

    private String simpleName;

    private Integer authorId;

    private Integer manufacturerId;

    private Integer switchTypeId;

    private String backgroundColor;

    private String color;

    public ServerResponse validate() {
        if (StringUtils.isBlank(this.name)) {
            return ServerResponse.createByErrorMessage("轴体名称不能为空");
        }
        if (StringUtils.isBlank(this.simpleName)) {
            return ServerResponse.createByErrorMessage("轴体简单名称不能为空");
        }
        if (this.authorId == null || this.authorId.equals(-1)) {
            this.authorId = null;
        }
        if (this.manufacturerId == null || this.manufacturerId.equals(-1)) {
            this.manufacturerId = null;
        }
        if (this.switchTypeId == null || this.switchTypeId.equals(-1)) {
            this.switchTypeId = null;
        }
        if (StringUtils.isBlank(this.backgroundColor)) {
            return ServerResponse.createByErrorMessage("轴体背景颜色不能为空");
        }
        return ServerResponse.createBySuccess();
    }
}
